#include "ASFreePay.h"

#define TEXT_BRIEF "\x67\x2c\x6b\x21\x4e\xa4\x66\x13\x65\x36\x53\xd6\x60\xa8\x0\x31\x0\x30\x0\x30\x4e\xe4\x72\x4c\x00\x00"//\xff\xc\x8d\x2d\x4e\x70\x5c\x60\x9f\x99\x5b\x9d\x52\x0\x30\x2\x0\xd\x0\xa\x5b\x9d\x52\x0\x5c\x5e\x60\x27\xff\x1a\x65\x3b\x51\xfb\x52\x9b\x0\x2b\x0\x31\x0\x30\x0\x30\x0\xd\x0\xa\x83\xb7\x53\xd6\x91\xd1\x94\xb1\x58\x9e\x52\xa0\x0\x31\x0\x30\x0\x30\x0\x25\xff\xc\x70\xb9\x51\xfb\x78\x6e\x5b\x9a\x8f\xdb\x88\x4c\x65\x2f\x4e\xd8\x30\x2
//#define TEXT_BRIEF	"\x67\x2c\x6b\x21\x65\x36\x53\xd6\x4f\x60\x0\x31\x0\x30\x0\x30\x0\x30\x4e\x2a\x51\x43\x5b\x9d\xff\xc\x8f\xd9\x66\x2f\x4e\x3a\x4e\xc0\x4e\x48\x54\x62\xff\x1f\x00\x00"
#define TEXT_DETAIL	"\x56\xe0\x4e\x3a\x5f\x0\x53\xd1\x8f\xd9\x4e\x2a\x63\xd2\x4e\xf6\x76\x84\x4e\xba\x95\x7f\x5f\x97\x59\x2a\x5e\x5\x4e\x86\xff\xc\x4e\xd\x71\x36\x5b\xf9\x4e\xd\x8d\x77\x4e\xd6\x90\x1d\x53\xbb\x76\x84\x97\x52\x66\x25\x55\x4a\xff\xc\x4f\x60\x8b\xf4\x66\x2f\x54\x27\xff\x1\xff\x1f\x00\x00"

static void __loadCB(int32 result);

static void __chargeResultCB(int32 result)
{
    mrc_clearScreen(0, 0, 0);

    if (MR_SUCCESS == result)
    {
        mrc_drawText("pay success!", 0, 0, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
    }
    else
    {
        mrc_drawText("pay failed!", 0, 0, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
    }

    mrc_refreshScreen(0, 0, 240, 320);
    __loadCB(MR_SUCCESS);
    //mrc_timerStart(mrc_timerCreate(), 1000, MR_SUCCESS, __loadCB, FALSE);
}

static void __loadCB(int32 result)
{
    if (MR_SUCCESS == result)
    {
        //FPRINTF("again demo memory remain = %d", mrc_getMemoryRemain());
        mrc_clearScreen(0, 0, 0);
        mrc_drawText("initialized.", 0, 0, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
        mrc_drawText("press 1 to charge reg.", 0, 24, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
        mrc_drawText("press 2 to charge property.", 0, 48, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
        mrc_drawText("press 3 to exit.", 0, 72, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
        mrc_refreshScreen(0, 0, 240, 320);
    }
}

void as_free_pay_init(void)
{
    mrc_freecurrency_init(TRUE, FALSE, __loadCB);
    mrc_freecurrency_reg_pay(0, 100, TEXT_BRIEF, TEXT_DETAIL, __chargeResultCB);
}

void as_free_pay_deinit(void)
{
    mrc_freecurrency_unload();
}